/*
 * @Author: xuetao 3168581151@qq.com
 * @Date: 2025-02-08
 * @LastEditors: xuetao 3168581151@qq.com
 * @LastEditTime: 2025-03-01
 * @Description: 
 */
import 'package:chat_client/config/api_config.dart';
import 'package:chat_client/providers/application_provider.dart';
import 'package:chat_client/screens/mobile/contact/contact_page.dart';
import 'package:provider/provider.dart';
import '/widgets/custom_global_widgets.dart';

import 'package:flutter/material.dart';

class BlockListScreen extends StatelessWidget {
  const BlockListScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text('黑名单列表')),
        body: _buildApplicationList());
  }

  Widget _buildApplicationList() {
    return Consumer<ApplicationProvider>(builder: (context, model, child) {
      if (model.blackList.isEmpty) {
        return const _EmptyBlackListHint();
      }
      return ListView.separated(
        itemCount: model.blackList.length,
        itemBuilder: (context, index) {
          return CListTile(
              imageUrl: AppConfig.baseUrl + model.blackList[index].avatarUrl,
              title: model.blackList[index].nickname,
              trailing: Icon(Icons.more_horiz),
              onTap: () => model.navToWidget(ContactScreen(
                  contact: model.blackList[index], isBlack: true)));
        },
        separatorBuilder: (context, index) {
          return Divider(height: 1);
        },
      );
    });
  }
}

class _EmptyBlackListHint extends StatelessWidget {
  const _EmptyBlackListHint();

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(
        '黑名单为空',
        style: Theme.of(context).textTheme.titleMedium?.copyWith(
              color: Colors.grey,
            ),
      ),
    );
  }
}
